package cn.g31010.sip.service
{
	import cn.g31010.sip.model.*;
	import cn.g31010.sip.vo.Room;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.managers.CursorManager;
	
	
	public class RoomManageService
	{
		private static var authservice:RoomManageService;
		private var rm:RoomModel=RoomModel.getInstance();
		public function RoomManageService()
		{
			if(RoomManageService.authservice!=null)
				throw new Error("Only one instance should be instantiated");
		}
		
		public static function getInstance():RoomManageService{
			if(authservice==null){
				authservice=new RoomManageService;
			}
			return authservice;
		}
		
		public function getAllRooms():ArrayCollection{
			return null;
		}
	
	public function findRoomById( id:String):Room{
		return null;
	}
	
	public function findRoomByName( name:String):ArrayCollection{
		return null;
	}
	
	public function addRoom(room:Room,callback:Function=null):void{
		var client:HessianClient=new HessianClient("RoomManageService",callback==null?addRoomResp:callback);
		client.request("addRoom",room);
	}
	private function addRoomResp(obj:Object):void{
			var room:Room = Room.create(obj);
               if(room!=null){
              		rm.addRoom(room);
              		Alert.show(room.id+"添加房间成功");
               }else{
               		Alert.show("添加房间失败");
               }
               CursorManager.removeBusyCursor();
		}
	
	public function setRoom(room:Room,callback:Function=null):void{
		var client:HessianClient=new HessianClient("RoomManageService",callback==null?setRoomResp:callback);
		client.request("setRoom",room);
	}
	private function setRoomResp(obj:Object):void{
		var room:Room = Room.create(obj);
               if(room!=null){
              		rm.removeRoom(room.id);
              		rm.addRoom(room);
              		Alert.show(room.id+"更新房间成功");
               }else{
               		Alert.show("更新房间失败");
               }
               CursorManager.removeBusyCursor();
	}
	
	public function removeRoom( id:String):Room{
		return null;
	}
	
	public function addAdmin( id:String, uid:String):Room{
		return null;
	}
	
	public function removeAdmin( id:String, uid:String):Room{
		return null;
	}
	
	public function addBlack( id:String, uid:String):Room{
		return null;
	}
	
	public function removeBlack( id:String, uid:String):Room{
		return null;
	}
	
	public function addWhite( id:String, uid:String):Room{
		return null;
	}
	
	public function removeWhite( id:String, uid:String):Room{
		return null;
	}
	
	public function setOwner( id:String, uid:String):Room{
		return null;
	}
	
	public function removeOwner( id:String, uid:String):Room{
		return null;
	}
	}
}